package ex55.mm.flow.impound.quote.common.kit;

import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.joda.time.format.ISODateTimeFormat;

import java.sql.Timestamp;
import java.util.Date;
import java.util.TimeZone;

public class DateTimeKit {
    static {
        TimeZone timeZone = TimeZone.getTimeZone("UTC");
        TimeZone.setDefault(timeZone);
    }


    public static Date newDate() {
        return DateTime.now().withZone(DateTimeZone.UTC).toDate();
    }

    public static Date newDate(long longValue) {
        return new DateTime(longValue).withZone(DateTimeZone.UTC).toDate();
    }

    public static Date nowPlusMinutes(int i) {
        return DateTime.now().withZone(DateTimeZone.UTC).plusMinutes(i).toDate();
    }

    public static Timestamp nowTimestamp() {
        return new Timestamp(System.currentTimeMillis());
    }

    public static String stringUTCDate(Date date) {
        return new DateTime(date).withZone(DateTimeZone.UTC).toString(ISODateTimeFormat.yearMonthDay());
    }

    public static String stringUTCBasicDate(Date date) {
        return new DateTime(date).withZone(DateTimeZone.UTC).toString(ISODateTimeFormat.basicDate());
    }

    public static String stringUTCISO8601(Date date) {
        return new DateTime(date).withZone(DateTimeZone.UTC).toString(ISODateTimeFormat.dateTime());
    }


    public static Date timeAtStartOfDay() {
        return DateTime.now().withZone(DateTimeZone.UTC).withTimeAtStartOfDay().toDate();
    }
}
